HTMLify
app.js
Views: 12 | Author: huxn-webdev
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | const genBtn = document.querySelector(".btn1"); const copyBtn = document.querySelector(".btn2"); genBtn.addEventListener("click", () => genPassword()); copyBtn.addEventListener("click", () => copyPassword()); function genPassword() { let chars = "0123456789abcdefghijklmnopqristuvwxyz!@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ"; passwordLength = 7; password = ""; for (let i = 0; i <= passwordLength; i++) { let randomNumber = Math.floor(Math.random() * chars.length); password += chars.substring(randomNumber, randomNumber + 1); } document.getElementById("password").value = password; } function copyPassword() { let copyText = document.getElementById("password"); copyText.select(); document.execCommand("copy"); } |